package com.mini.demos.webgame.codec;

import org.apache.mina.core.buffer.IoBuffer;

import com.mini.demos.webgame.msg.AbstractGameMsg;
import com.mini.demos.webgame.msg.LoginMsg;
import com.mini.demos.webgame.util.CommandConstants;
import com.mini.demos.webgame.util.Constants;
import com.mini.framework.communicate.mina.protocol.Msg;

public class LoginEncoder extends AbstractEncoder {

	@Override
	public void encodeBody(AbstractGameMsg msg, IoBuffer buffer) {
		LoginMsg login = (LoginMsg)msg;
		try{
			buffer.putString(login.getName(), Constants.charset.newEncoder());
			buffer.putString(CommandConstants.COMMAND_SPLIT, Constants.charset.newEncoder());
			buffer.putString(login.getPwd(), Constants.charset.newEncoder());
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	@Override
	public Class<? extends Msg> getMsgType() {
		return LoginMsg.class;
	}

}
